package com.demo.supplier.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * MyBatis-Plus字段自动填充处理器
 * 
 * @author demo
 */
@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        
        // TODO: 这里可以从当前登录用户获取用户ID
        // Long currentUserId = getCurrentUserId();
        // this.strictInsertFill(metaObject, "createBy", Long.class, currentUserId);
        // this.strictInsertFill(metaObject, "updateBy", Long.class, currentUserId);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        
        // TODO: 这里可以从当前登录用户获取用户ID
        // Long currentUserId = getCurrentUserId();
        // this.strictUpdateFill(metaObject, "updateBy", Long.class, currentUserId);
    }
}